package binary_search;

/**
 * 寻找旋转排序数组中的最小值
 */

public class Demo20250403 {
    public int findMin(int[] nums) {
        // 以左端点为参照物
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[left] < nums[right]) {
                return nums[left];
            }
            if (nums[mid] >= nums[left]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left];




        // // 以右端点作为参照物
        // int left = 0, right = nums.length - 1;
        // while (left < right) {
        //     int mid = left + (right - left) / 2 ;
        //     if (nums[mid] > nums[right]) {
        //         left = mid + 1;
        //     } else {
        //         right = mid;
        //     }
        // }
        // return nums[left];
    }
}
